﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JGSY.WinAlarmManage
{
    /// <summary>
    /// 从站信息类
    /// </summary>
    public class SlaveInfo
    {
        /// <summary>
        /// 
        /// </summary>
        public byte SlaveId { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public byte FuntionCode { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public ushort StartAddress { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public ushort Count { get; set; }
    }
    /// <summary>
    /// 参数信息类
    /// </summary>
    public class ParaInfo
    {
        /// <summary>
        /// 
        /// </summary>
        public string ParaName { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public byte SlaveId { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public ushort Address { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string DataType { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string Note { get; set; }
    }
    /// <summary>
    /// 预警设置信息类
    /// </summary>
    public class AlarmInfo
    {
        /// <summary>
        /// 
        /// </summary>
        public string ParaType { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int AlarmType { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string AlarmValue { get; set; }
    }
    /// <summary>
    /// 预警记录信息类
    /// </summary>
    public class AlarmLogInfo
    {
        /// <summary>
        /// 
        /// </summary>
        public int Id { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public DateTime AlarmTime { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string ParaName { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int AlarmType { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string AlarmTypeText { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string AlarmState { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int Value { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string AlarmNote { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public AlarmLogInfo(int id, DateTime alarmTime, string paraName, int alarmType, string alarmState, int value, string alarmNote, string alarmTypeText = "")
        {
            Id = id;
            AlarmTime = alarmTime;
            ParaName = paraName;
            AlarmState = alarmState;
            AlarmType = alarmType;
            if (AlarmState == "HAlarm")
            {
                AlarmTypeText = "高值报警";

            }
            else if (AlarmState == "LAlarm")
            {
                AlarmTypeText = "低值报警";
            }
            else
            {
                AlarmTypeText = "报警解除";
            }

            Value = value;
            AlarmNote = alarmNote;
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class CommonClass
    {
        /// <summary>
        /// 
        /// </summary>
        public static List<AlarmLogInfo> logList = new List<AlarmLogInfo>();//存储预警记录信息

        /// <summary>
        /// 
        /// </summary>
        public static event Action UpdateAlarmLogList;//更新预警列表
        
        /// <summary>
        /// 调用更新事件
        /// </summary>
        public static void UpdateDgvAlarmList()
        {
            UpdateAlarmLogList?.Invoke();
        }
    }
}
